// 用户池
const users=[
    {username:'张丽',password:'123456789'},
    {username:'赵丽颖',password:'223456789'},
    {username:'肖战',password:'323456789'}
];
// 列表数据
const assetsLists=[
        {
            sendMsgName: '发送账号01',
            sendPwd: '密码01',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'000001',
            date: '2016-10-03',
            operator:'张三01'                    
        },
        {
            sendMsgName: '发送账号02',
            sendPwd: '密码02',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'000002',
            date: '2016-10-03',
            operator:'张三02'                    
        },
        {
            sendMsgName: '发送账号03',
            sendPwd: '密码03',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'000003',
            date: '2016-10-03',
            operator:'张三03'                    
        },
        {
            sendMsgName: '发送账号04',
            sendPwd: '密码04',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三04'                    
        },
        {
            sendMsgName: '发送账号05',
            sendPwd: '密码05',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三05'                    
        },
        {
            sendMsgName: '发送账号06',
            sendPwd: '密码06',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三06'                    
        },
        {
            sendMsgName: '发送账号07',
            sendPwd: '密码07',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三07'                    
        },
        {
            sendMsgName: '发送账号08',
            sendPwd: '密码08',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三08'                    
        },
        {
            sendMsgName: '发送账号09',
            sendPwd: '密码09',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三09'                    
        },
        {
            sendMsgName: '发送账号10',
            sendPwd: '密码10',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三10'                    
        },
        {
            sendMsgName: '发送账号11',
            sendPwd: '密码11',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三11'                    
        },
        {
            sendMsgName: '发送账号12',
            sendPwd: '密码12',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三12'                    
        },
        {
            sendMsgName: '发送账号13',
            sendPwd: '密码13',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三13'                    
        },
        {
            sendMsgName: '发送账号14',
            sendPwd: '密码14',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三14'                    
        },
        {
            sendMsgName: '发送账号15',
            sendPwd: '密码15',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三15'                    
        },
        {
            sendMsgName: '发送账号16',
            sendPwd: '密码16',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三16'                    
        },
        {
            sendMsgName: '发送账号17',
            sendPwd: '密码17',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三17'                    
        },
        {
            sendMsgName: '发送账号18',
            sendPwd: '密码18',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三18'                    
        },
        {
            sendMsgName: '发送账号19',
            sendPwd: '密码19',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三19'                    
        },
        {
            sendMsgName: '发送账号20',
            sendPwd: '密码20',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三20'                    
        },
        {
            sendMsgName: '发送账号21',
            sendPwd: '密码21',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三21'                    
        },
        {
            sendMsgName: '发送账号22',
            sendPwd: '密码22',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三22'                    
        },
        {
            sendMsgName: '发送账号23',
            sendPwd: '密码23',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"1",
            user:'所属客户',
            date: '2016-10-03',
            operator:'张三23'                    
        },
        {
            sendMsgName: '发送账号24',
            sendPwd: '密码24',
            type:'通知短信',
            loginName:'登录账号名称',
            loginPwd:'登录账号密码',
            status:"0",
            user:'',
            date: '2016-10-03',
            operator:'张三24'                    
        },
    ]
// 编写token值
const tokenKey='u34g5g4788bj9h9b2101';
module.exports={
    devServer:{
        before(app,server){
            // 登录api
            app.get('/api/login',(req,res)=>{
                let {username,password}=req.query;
                let flag=users.some(item=>{
                    return item.username===username&&item.password===password;
                });
                if(flag){
                    res.json({
                        code:0,
                        message:'登录成功！',
                        userName:username,
                        token:tokenKey+'-'+username+'-'+(new Date().getTime()+60*60*1000)
                    })
                }else{
                    res.json({
                        code:1,
                        message:'账号或者密码错误！'
                    })
                }
            })
            // 模拟用户列表信息+分页的api
            app.get('/api/assetsLists',(req,res)=>{
                let {query,pagenum,pagesize}=req.query;
                let total=0;
                let getDataList=[];
                if(query!=''){
                    total=assetsLists.length;
                    if(pagenum==0){
                        getDataList=assetsLists.filter(val=>val.sendMsgName===query).slice(pagenum*pagesize,(parseInt(pagenum)+1)*pagesize);                        
                    }else{
                        getDataList=assetsLists.filter(val=>val.sendMsgName===query).slice((parseInt(pagenum)-1)*pagesize,pagenum*pagesize);
                    }
                    res.json({
                        'status':'ok',
                        'total':total,
                        'data':getDataList
                    })
                }else{
                    total=assetsLists.length;
                    if(pagenum==0){
                        getDataList=assetsLists.slice(pagenum*pagesize,(parseInt(pagenum+1)*pagesize));
                    }else{
                        getDataList=assetsLists.slice(parseInt(pagenum-1)*pagesize,pagenum*pagesize);
                    }
                    res.json({
                        'status':'ok',
                        'total':total,
                        'data':getDataList
                    })
                }
            })
        }
    }
}   